package com.share.shareplatform.sharegoods.controller;

import com.share.shareplatform.pojo.exception.LogicException;
import com.share.shareplatform.sharegoods.service.CommentOneLikeService;
import com.share.shareplatform.util.AuthorityUtil;
import com.share.shareplatform.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;

@RestController
@RequestMapping("/commentOneLike")
@Validated
public class CommentOneLikeController {


    @Autowired
    private CommentOneLikeService commentOneLikeService;

    @ApiOperation(value = "点赞")
    @GetMapping("/goc/inc/{commentId}")
    public Result increaseCount(@PathVariable("commentId") Long commentId){
        Long userId = 34l;
        int i = commentOneLikeService.updateCount(1, commentId, userId);
        if(i>0){
            return Result.getInstance(200,"success");
        }
        throw new LogicException("你已经点过赞了");
    }

    @ApiOperation(value = "取消点赞")
    @GetMapping("/goc/desc/{commentId}")

    public Result descCount(@PathVariable("commentId") Long commentId){
        Long userId = 34l;
        int i =commentOneLikeService.updateCount(-1, commentId, userId);
        if(i>0){
            return Result.getInstance(200,"success");
        }
        throw new LogicException("你还未点赞");
    }

}
